FROM dorowu/ubuntu-desktop-lxde-vnc:xenial

USER root

ENV DEBIAN_FRONTEND noninteractive
ENV LANG=C.UTF-8 LC_ALL=C.UTF-8
ENV HOME=/root SHELL=/bin/bash

########### 1. 换源、安装基础软件 ###########
COPY    ${PWD}/source/etc/apt/sources.list /etc/apt/sources.list
RUN     rm -f /etc/apt/sources.list.d/*
RUN     apt update

RUN     apt install -y --no-install-recommends --allow-unauthenticated \
        dpkg pkg-config apt-utils \
        # 基础软件
        software-properties-common \
        dirmngr gnupg2 \
        # 远程
        openssh-server \
        # 下载 网络
        axel aria2 net-tools \
        # 文本操作
        gedit vim grep sed patch \
        # 压缩软件
        pv zip unzip bzip2 unrar\
        # 版本控制
        git \
        # 编译相关
        gcc g++ \
        make cmake build-essential autoconf automake libtool \
        libglib2.0-dev libboost-dev libboost-all-dev libtbb-dev

########### 2. 安装 ros-kinetic ###########
COPY    ${PWD}/source/etc/apt/sources.list.d/ros-latest.list /etc/apt/sources.list.d/ros-latest.list
RUN     apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
RUN     apt update
RUN     apt install -y --no-install-recommends --allow-unauthenticated \
        ros-kinetic-desktop-full \
        python-rosdep python-rosinstall python-rosinstall-generator python-wstool

WORKDIR /root
RUN     echo "source /opt/ros/kinetic/setup.bash\n" >>/root/.bashrc
COPY    ${PWD}/source/rosdistro-master-local.zip /root
RUN     unzip rosdistro-master-local.zip
RUN     mkdir -p /etc/ros/rosdep/sources.list.d
RUN     cp -f /root/rosdistro-master/rosdep/sources.list.d/20-default.list /etc/ros/rosdep/sources.list.d/
RUN     sed -i "s|https://raw.githubusercontent.com/ros/rosdistro/master|file:///root/rosdistro-master|g" /etc/ros/rosdep/sources.list.d/20-default.list
RUN     sed -i "s|https://raw.githubusercontent.com/ros/rosdistro/master|file:///root/rosdistro-master|g" /usr/lib/python2.7/dist-packages/rosdep2/gbpdistro_support.py
RUN     sed -i "s|https://raw.githubusercontent.com/ros/rosdistro/master|file:///root/rosdistro-master|g" /usr/lib/python2.7/dist-packages/rosdep2/rep3.py
RUN     sed -i "s|https://raw.githubusercontent.com/ros/rosdistro/master|file:///root/rosdistro-master|g" /usr/lib/python2.7/dist-packages/rosdistro/__init__.py
RUN     rosdep update
RUN     rm -rf rosdistro-master rosdistro-master-local.zip
RUN     sed -i "s|file:///root/rosdistro-master|https://raw.githubusercontent.com/ros/rosdistro/master|g" /etc/ros/rosdep/sources.list.d/20-default.list
RUN     sed -i "s|file:///root/rosdistro-master|https://raw.githubusercontent.com/ros/rosdistro/master|g" /usr/lib/python2.7/dist-packages/rosdep2/gbpdistro_support.py
RUN     sed -i "s|file:///root/rosdistro-master|https://raw.githubusercontent.com/ros/rosdistro/master|g" /usr/lib/python2.7/dist-packages/rosdep2/rep3.py
RUN     sed -i "s|file:///root/rosdistro-master|https://raw.githubusercontent.com/ros/rosdistro/master|g" /usr/lib/python2.7/dist-packages/rosdistro/__init__.py

WORKDIR /root

RUN     apt install -y --no-install-recommends --allow-unauthenticated \
        libeigen3-dev \
        libpcl1-dev \
        # ceres dep
        libgoogle-glog-dev libgflags-dev libatlas-base-dev libsuitesparse-dev

########### 3. 安装 gtsam ###########
COPY    ${PWD}/source/thirdparty/gtsam.tar.xz /root
RUN     tar xvJf gtsam.tar.xz && cd gtsam && \
        mkdir build && cd build && \
        cmake .. && \
        make -j3 && \
        make install
RUN     rm -rf gtsam.tar.xz gtsam

########### 4. 安装 kitti2bag evo 评估工具 ###########
# pip 换源
WORKDIR /root
COPY    ${PWD}/source/etc/pip.conf /root/.pip/pip.conf
COPY    ${PWD}/source/get-pip.py /root
RUN     python get-pip.py
# kitti2bag
RUN     pip install pandas==0.23.0 pykitti kitti2bag
# evo
RUN     pip install matplotlib==1.5.3
RUN     pip install evo --upgrade --no-binary evo